// 1.在执行完new,生成实例后
var hook = {
  args: [
    "name",
    "age",
  ],
  taps: [
  ],
  call: function (...args) {
    this.call = this._createCall('sync');//调用它的时候 ，它会动态创建call函数，重写this.call属性
    return this.call(...args);//执行新创建的call方法，
  },
  callAsync: function (...args) {
    this.callAsync = this._createCall('async');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.callAsync(...args);//执行新创建的call方法，
  },
  promise: function (...args) {
    this.promise = this._createCall('promise');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.promise(...args);//执行新创建的call方法，
  },
  interceptors: [
  ],
}
// 2.执行hook.tapAsync过程中生成的tapInfo
const tapInfo = {
  name: "1",
  type: "async",
  fn: (name,age,callback)=>{
    setTimeout(()=>{
      console.log(1,name,age);
      callback();
    },1000);
  },
}
// 3.执行hook.tapAsync结束后，此时实例为
hook = {
  args: [
    "name",
    "age",
  ],
  taps: [
    {
      name: "1",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(1,name,age);
          callback();
        },1000);
      },
    },
    {
      name: "2",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(2,name,age);
          callback();
        },2000);
      },
    },
    {
      name: "3",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(3,name,age);
          callback();
        },3000);
      },
    },
  ],
  call: function (...args) {
    this.call = this._createCall('sync');//调用它的时候 ，它会动态创建call函数，重写this.call属性
    return this.call(...args);//执行新创建的call方法，
  },
  callAsync: function (...args) {
    this.callAsync = this._createCall('async');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.callAsync(...args);//执行新创建的call方法，
  },
  promise: function (...args) {
    this.promise = this._createCall('promise');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.promise(...args);//执行新创建的call方法，
  },
  interceptors: [
  ],
}
// 4.执行hook.callAsync生成的hook实例为
hook = {
  args: [
    "name",
    "age",
  ],
  taps: [
    {
      name: "1",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(1,name,age);
          callback();
        },1000);
      },
    },
    {
      name: "2",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(2,name,age);
          callback();
        },2000);
      },
    },
    {
      name: "3",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(3,name,age);
          callback();
        },3000);
      },
    },
  ],
  call: function (...args) {
    this.call = this._createCall('sync');//调用它的时候 ，它会动态创建call函数，重写this.call属性
    return this.call(...args);//执行新创建的call方法，
  },
  callAsync: function (...args) {
    this.callAsync = this._createCall('async');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.callAsync(...args);//执行新创建的call方法，
  },
  promise: function (...args) {
    this.promise = this._createCall('promise');//调用它的时候 ，它会动态创建callAsync函数，重写this.callAsync属性
    return this.promise(...args);//执行新创建的call方法，
  },
  interceptors: [
  ],
  _x: [
    (name,age,callback)=>{
      setTimeout(()=>{
        console.log(1,name,age);
        callback();
      },1000);
    },
    (name,age,callback)=>{
      setTimeout(()=>{
        console.log(2,name,age);
        callback();
      },2000);
    },
    (name,age,callback)=>{
      setTimeout(()=>{
        console.log(3,name,age);
        callback();
      },3000);
    },
  ],
}
// 5.执行factory.create传入的参数options为
options = {
  taps: [
    {
      name: "1",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(1,name,age);
          callback();
        },1000);
      },
    },
    {
      name: "2",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(2,name,age);
          callback();
        },2000);
      },
    },
    {
      name: "3",
      type: "async",
      fn: (name,age,callback)=>{
        setTimeout(()=>{
          console.log(3,name,age);
          callback();
        },3000);
      },
    },
  ],
  args: [
    "name",
    "age",
  ],
  interceptors: [
  ],
  type: "async",
}
// 6.生成函数，并且传入参数(...args)执行
(function anonymous(name, age, _callback) {
  var _x = this._x;
  var _counter = 3; //计数器
  var _done = function () {
    _callback();    //表示call方法全部执行结束
  };
  var _fn0 = _x[0];
  _fn0(name, age, function () {
    if (--_counter === 0) _done();
  });
  var _fn1 = _x[1];
  _fn1(name, age, function () {
    if (--_counter === 0) _done();
  });
  var _fn2 = _x[2];
  _fn2(name, age, function () {
    if (--_counter === 0) _done();
  });
})(...args)